/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "plugins/ecmascript/runtime/base/builtins_base.h"
#include "plugins/ecmascript/runtime/base/number_helper.h"
#include "plugins/ecmascript/runtime/ecma_macros.h"
#include "plugins/ecmascript/runtime/global_env.h"
#include "plugins/ecmascript/runtime/js_arraybuffer.h"
#include "plugins/ecmascript/runtime/js_tagged_number.h"
#include "plugins/ecmascript/runtime/js_tagged_value-inl.h"
#include "plugins/ecmascript/runtime/js_tagged_value.h"

namespace ark::ecmascript::builtins {
// 24.2.2.1
JSTaggedValue data_view::DataViewConstructor(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    BUILTINS_API_TRACE(argv->GetThread(), DataView, DataViewConstructor);
    JSThread *thread = argv->GetThread();
    [[maybe_unused]] EcmaHandleScope handleScope(thread);
    JSHandle<JSTaggedValue> ctor = builtins_common::GetConstructor(argv);
    JSHandle<JSTaggedValue> newTarget = builtins_common::GetNewTarget(argv);
    // 1. If NewTarget is undefined, throw a TypeError exception.
    if (newTarget->IsUndefined()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "newtarget is undefined", JSTaggedValue::Exception());
    }
    JSHandle<JSTaggedValue> bufferHandle = builtins_common::GetCallArg(argv, 0);
    // 2. If Type(buffer) is not Object, throw a TypeError exception.
    if (!bufferHandle->IsECMAObject()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not Object", JSTaggedValue::Exception());
    }
    // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception.
    if (!bufferHandle->IsArrayBuffer()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not ArrayBuffer", JSTaggedValue::Exception());
    }
    JSHandle<JSTaggedValue> offsetHandle = builtins_common::GetCallArg(argv, 1);
    // 4. Let numberOffset be ToNumber(byteOffset).
    JSTaggedNumber offsetNumber = JSTaggedValue::ToNumber(thread, offsetHandle);
    // 6. ReturnIfAbrupt(offset).
    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
    int32_t offset = ecmascript::base::NumberHelper::DoubleInRangeInt32(offsetNumber.GetNumber());
    // 7. If numberOffset ≠ offset or offset < 0, throw a RangeError exception.
    if (offset < 0) {
        THROW_RANGE_ERROR_AND_RETURN(thread, "Offset out of range", JSTaggedValue::Exception());
    }
    // 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
    if (builtins::array_buffer::IsDetachedBuffer(bufferHandle.GetTaggedValue())) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception());
    }
    // 9. Let bufferByteLength be the value of buffer’s [[ArrayBufferByteLength]] internal slot.
    JSHandle<JSArrayBuffer> arrBufHandle(bufferHandle);
    JSTaggedNumber bufLenNum = JSTaggedNumber::FromIntOrDouble(thread, arrBufHandle->GetArrayBufferByteLength());
    int32_t bufByteLen = bufLenNum.ToInt32();
    // 10. If offset > bufferByteLength, throw a RangeError exception.
    if (offset > bufByteLen) {
        THROW_RANGE_ERROR_AND_RETURN(thread, "offset > bufferByteLength", JSTaggedValue::Exception());
    }
    int32_t viewByteLen;
    JSHandle<JSTaggedValue> byteLenHandle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD);
    // 11. If byteLength is undefined, then Let viewByteLength be bufferByteLength – offset.
    if (byteLenHandle->IsUndefined()) {
        viewByteLen = bufByteLen - offset;
    } else {
        // Let viewByteLength be ToIndex(byteLength).
        JSTaggedNumber byteLen = JSTaggedValue::ToIndex(thread, byteLenHandle);
        // ReturnIfAbrupt(viewByteLength).
        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
        viewByteLen = byteLen.ToInt32();
        // If offset+viewByteLength > bufferByteLength, throw a RangeError exception.
        if (offset + viewByteLen > bufByteLen) {
            THROW_RANGE_ERROR_AND_RETURN(thread, "offset + viewByteLen > bufByteLen", JSTaggedValue::Exception());
        }
    }
    // 13. Let O be OrdinaryCreateFromConstructor OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
    // «[[DataView]],[[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]]» ).
    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
    JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), newTarget);
    // 14. ReturnIfAbrupt(O).
    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
    JSHandle<JSDataView> dataView(obj);
    // 15. Set O’s [[DataView]] internal slot to true.
    dataView->SetDataView(thread, JSTaggedValue::True());
    // 16. Set O’s [[ViewedArrayBuffer]] internal slot to buffer.
    dataView->SetViewedArrayBuffer(thread, bufferHandle.GetTaggedValue());
    // 17. Set O’s [[ByteLength]] internal slot to viewByteLength.
    dataView->SetByteLength(thread, JSTaggedValue(viewByteLen));
    // 18. Set O’s [[ByteOffset]] internal slot to offset.
    dataView->SetByteOffset(thread, JSTaggedValue(offset));
    // 19. Return O.
    return JSTaggedValue(dataView.GetTaggedValue());
}

// 24.2.4.1
JSTaggedValue data_view::proto::GetBuffer(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    BUILTINS_API_TRACE(argv->GetThread(), DataViewPrototype, GetBuffer);
    JSThread *thread = argv->GetThread();
    [[maybe_unused]] EcmaHandleScope handleScope(thread);
    // 1. Let O be the this value.
    JSHandle<JSTaggedValue> thisHandle = builtins_common::GetThis(argv);
    // 2. f Type(O) is not Object, throw a TypeError exception.
    if (!thisHandle->IsECMAObject()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
    }
    // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception.
    if (!thisHandle->IsDataView()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception());
    }
    JSHandle<JSDataView> dataView(thisHandle);
    // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
    JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
    // 5. Return buffer.
    return JSTaggedValue(buffer);
}

// 24.2.4.2
JSTaggedValue data_view::proto::GetByteLength(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    BUILTINS_API_TRACE(argv->GetThread(), DataViewPrototype, GetByteLength);
    JSThread *thread = argv->GetThread();
    [[maybe_unused]] EcmaHandleScope handleScope(thread);
    // 1. Let O be the this value.
    JSHandle<JSTaggedValue> thisHandle = builtins_common::GetThis(argv);
    // 2. If Type(O) is not Object, throw a TypeError exception.
    if (!thisHandle->IsECMAObject()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
    }
    // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception.
    if (!thisHandle->IsDataView()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception());
    }
    JSHandle<JSDataView> dataView(thisHandle);
    // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
    JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
    // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
    if (builtins::array_buffer::IsDetachedBuffer(buffer)) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
    }
    // 6. Let size be the value of O’s [[ByteLength]] internal slot.
    JSTaggedValue size = dataView->GetByteLength();
    // 7. Return size.
    return JSTaggedValue(size);
}

// 24.2.4.3
JSTaggedValue data_view::proto::GetByteOffset(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    BUILTINS_API_TRACE(argv->GetThread(), DataViewPrototype, GetByteOffset);
    JSThread *thread = argv->GetThread();
    [[maybe_unused]] EcmaHandleScope handleScope(thread);
    // 1. Let O be the this value.
    JSHandle<JSTaggedValue> thisHandle = builtins_common::GetThis(argv);
    // 2. If Type(O) is not Object, throw a TypeError exception.
    if (!thisHandle->IsECMAObject()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
    }
    // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception.
    if (!thisHandle->IsDataView()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception());
    }
    JSHandle<JSDataView> dataView(thisHandle);
    // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
    JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
    // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
    if (builtins::array_buffer::IsDetachedBuffer(buffer)) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
    }
    // 6. Let offset be the value of O’s [[ByteOffset]] internal slot.
    JSTaggedValue offset = dataView->GetByteOffset();
    // 7. Return offset.
    return JSTaggedValue(offset);
}

// 24.2.1.1
static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
                                  const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
                                  DataViewType type)
{
    BUILTINS_API_TRACE(thread, DataView, GetViewValue);
    // 1. If Type(view) is not Object, throw a TypeError exception.
    if (!view->IsECMAObject()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
    }
    // 2. If view does not have a [[DataView]] internal slot, throw a TypeError exception.
    if (!view->IsDataView()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception());
    }
    // 3. Let numberIndex be ToNumber(requestIndex).
    JSTaggedNumber numberIndex = JSTaggedValue::ToNumber(thread, requestIndex);
    // 5. ReturnIfAbrupt(getIndex).
    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
    int64_t index = ecmascript::base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
    // 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
    if (index < 0) {
        THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
    }
    // 7. Let isLittleEndian be ToBoolean(isLittleEndian).
    bool isLittleEndian;
    if (littleEndian.IsUndefined()) {
        isLittleEndian = false;
    } else {
        isLittleEndian = littleEndian.ToBoolean();
    }
    // 8. Let buffer be the value of view’s [[ViewedArrayBuffer]] internal slot.
    JSHandle<JSDataView> dataView(view);
    {
        // We use buffer without handle and GC can move it. So we have to get buffer each time.
        // To make developer get buffer each time use scope and don't populate buffer into function's scope.
        JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
        // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
        if (builtins::array_buffer::IsDetachedBuffer(buffer)) {
            THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
        }
    }
    // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot.
    JSTaggedNumber offsetNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteOffset());
    int32_t offset = offsetNum.ToInt32();
    // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot.
    JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength());
    int32_t size = viewNum.ToInt32();
    // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type.
    int32_t elementSize = JSDataView::GetElementSize(type);
    // 13. If getIndex +elementSize > viewSize, throw a RangeError exception.
    if (index + elementSize > size) {
        THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception());
    }
    // 14. Let bufferIndex be getIndex + viewOffset.
    int32_t bufferIndex = index + offset;
    // 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
    {
        // We use buffer without handle and GC can move it. So we have to get buffer each time.
        // To make developer get buffer each time use scope and don't populate buffer into function's scope.
        JSHandle<JSTaggedValue> buffer(thread, dataView->GetViewedArrayBuffer());
        return builtins::array_buffer::GetValueFromBuffer(thread, buffer, bufferIndex, type, isLittleEndian);
    }
}

// 24.2.1.2
JSTaggedValue SetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
                           const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian, DataViewType type,
                           const JSHandle<JSTaggedValue> &value)
{
    // 1. If Type(view) is not Object, throw a TypeError exception.
    BUILTINS_API_TRACE(thread, DataView, SetViewValue);
    if (!view->IsECMAObject()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
    }
    // 2. If view does not have a [[DataView]] internal slot, throw a TypeError exception.
    if (!view->IsDataView()) {
        THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception());
    }
    // 3. Let numberIndex be ToNumber(requestIndex).
    JSTaggedNumber numberIndex = JSTaggedValue::ToIndex(thread, requestIndex);
    // 5. ReturnIfAbrupt(getIndex).
    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
    int64_t index = ecmascript::base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
    // 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
    if (index < 0) {
        THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
    }
    JSHandle<JSTaggedValue> numVal = JSTaggedValue::ToNumeric(thread, value);
    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
    // 7. Let isLittleEndian be ToBoolean(isLittleEndian).
    bool isLittleEndian;
    if (littleEndian.IsUndefined()) {
        isLittleEndian = false;
    } else {
        isLittleEndian = littleEndian.ToBoolean();
    }
    // 8. Let buffer be the value of view’s [[ViewedArrayBuffer]] internal slot.
    JSHandle<JSDataView> dataView(view);
    {
        // We use buffer without handle and GC can move it. So we have to get buffer each time.
        // To make developer get buffer each time use scope and don't populate buffer into function's scope.
        JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
        // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
        if (builtins::array_buffer::IsDetachedBuffer(buffer)) {
            THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
        }
    }
    // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot.
    JSTaggedNumber offsetNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteOffset());
    int32_t offset = offsetNum.ToInt32();
    // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot.
    JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength());
    int32_t size = viewNum.ToInt32();
    // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type.
    int32_t elementSize = JSDataView::GetElementSize(type);
    // 13. If getIndex +elementSize > viewSize, throw a RangeError exception.
    if (index + elementSize > size) {
        THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception());
    }
    // 14. Let bufferIndex be getIndex + viewOffset.
    int32_t bufferIndex = index + offset;
    {
        // We use buffer without handle and GC can move it. So we have to get buffer each time.
        // To make developer get buffer each time use scope and don't populate buffer into function's scope.
        JSHandle<JSTaggedValue> buffer(thread, dataView->GetViewedArrayBuffer());
        // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian).
        return builtins::array_buffer::SetValueInBuffer(thread, buffer, bufferIndex, type, numVal, isLittleEndian);
    }
}

JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type)
{
    JSThread *thread = argv->GetThread();
    [[maybe_unused]] EcmaHandleScope handleScope(thread);
    JSHandle<JSTaggedValue> thisHandle = builtins_common::GetThis(argv);
    JSHandle<JSTaggedValue> offsetHandle = builtins_common::GetCallArg(argv, 0);
    if (type == DataViewType::UINT8 || type == DataViewType::INT8) {
        return GetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type);
    }
    JSHandle<JSTaggedValue> littleEndianHandle = builtins_common::GetCallArg(argv, 1);
    return GetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type);
}

JSTaggedValue SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type)
{
    JSThread *thread = argv->GetThread();
    [[maybe_unused]] EcmaHandleScope handleScope(thread);
    JSHandle<JSTaggedValue> thisHandle = builtins_common::GetThis(argv);
    JSHandle<JSTaggedValue> offsetHandle = builtins_common::GetCallArg(argv, 0);
    JSHandle<JSTaggedValue> value = builtins_common::GetCallArg(argv, 1);
    if (type == DataViewType::UINT8 || type == DataViewType::INT8) {
        return SetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type, value);
    }
    JSHandle<JSTaggedValue> littleEndianHandle =
        builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD);
    return SetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type, value);
}

// 24.2.4.5
JSTaggedValue data_view::proto::GetFloat32(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::FLOAT32);
}

// 24.2.4.6
JSTaggedValue data_view::proto::GetFloat64(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::FLOAT64);
}

// 24.2.4.7
JSTaggedValue data_view::proto::GetInt8(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::INT8);
}

// 24.2.4.8
JSTaggedValue data_view::proto::GetInt16(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::INT16);
}

// 24.2.4.9
JSTaggedValue data_view::proto::GetInt32(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::INT32);
}

// 24.2.4.10
JSTaggedValue data_view::proto::GetUint8(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::UINT8);
}

// 24.2.4.11
JSTaggedValue data_view::proto::GetUint16(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::UINT16);
}

// 24.2.4.12
JSTaggedValue data_view::proto::GetUint32(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::UINT32);
}

// 25.3.4.5
JSTaggedValue data_view::proto::GetBigInt64(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::BIGINT64);
}

// 25.3.4.6
JSTaggedValue data_view::proto::GetBigUint64(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return GetTypedValue(argv, DataViewType::BIGUINT64);
}

// 24.2.4.13
JSTaggedValue data_view::proto::SetFloat32(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::FLOAT32);
}

// 24.2.4.14
JSTaggedValue data_view::proto::SetFloat64(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::FLOAT64);
}

// 24.2.4.15
JSTaggedValue data_view::proto::SetInt8(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::INT8);
}

// 24.2.4.16
JSTaggedValue data_view::proto::SetInt16(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::INT16);
}

// 24.2.4.17
JSTaggedValue data_view::proto::SetInt32(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::INT32);
}

// 24.2.4.18
JSTaggedValue data_view::proto::SetUint8(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::UINT8);
}

// 24.2.4.19
JSTaggedValue data_view::proto::SetUint16(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::UINT16);
}

// 25.3.4.15
JSTaggedValue data_view::proto::SetBigInt64(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::BIGINT64);
}

// 25.3.4.16
JSTaggedValue data_view::proto::SetBigUint64(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::BIGUINT64);
}

// 24.2.4.20
JSTaggedValue data_view::proto::SetUint32(EcmaRuntimeCallInfo *argv)
{
    ASSERT(argv);
    return SetTypedValue(argv, DataViewType::UINT32);
}

}  // namespace ark::ecmascript::builtins
